import React, { useState, useEffect, useContext } from 'react';
import { Input, Menu, Dropdown, Button } from 'antd';
import { DownOutlined, SearchOutlined } from '@ant-design/icons';
import { AppContext } from '@/context'; // 假设有一个AppContext提供语言设置
import { Bell, Logo } from '../../img/svgComponent';
import getCurrentUser from '@components/getCurrentUser';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import './index.scss';

const Header = () => {
  const navigate = useNavigate();
  const [currentUser, setCurrentUser] = useState({});
  const [searchName, setSearchName] = useState("");
  const { t } = useTranslation();
 // const {userInfo,setUserInfo} =useContext(AppContext)
  // useEffect(() => {
  //   // 获取当前用户
  //   getCurrentUser().then(currentUser => {
  //
  //     if (!currentUser){
  //       setUserInfo(null)
  //       return;
  //     }
  //     setCurrentUser(currentUser);
  //     setUserInfo(currentUser)
  //   });
  // }, []);

  const searchChange = (e) => {
    setSearchName(e.target.value);
  };
  const goToLogin = () => {
    // 跳转到登录页
    window.open(globalInitConfig.eap_url,'_self')
  };
  const menuClick = ({ key }) => {
      if (key === "userInfo") {
          window.open(`/personal_data`, "_self");
          return;
      }
      if (key === "waxberry") {
          window.open(`/my_waxberry`, "_self");
          return;
      }
      if (key === "logout") {
          window.open(`${globalInitConfig.eap_url}doLogOut`, "_self");
      }
  };

  const items = [
    {
      key: 'userInfo',
      label: (
        <div>
          <svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" fill="none" version="1.1" width="16" height="16" viewBox="0 0 16 16">
            <defs>
              <clipPath id="master_svg0_65_3376">
                <rect x="0" y="0" width="16" height="16" rx="0"/>
              </clipPath>
            </defs>
            <g clipPath="url(#master_svg0_65_3376)">
              <g><path d="M12.8671,6.26171C12.8671,6.54575,12.6321,6.776,12.3421,6.776L9.4623,6.776C9.17235,6.776,8.9373,6.54575,8.9373,6.26171C8.9373,5.977679999999999,9.17235,5.74743,9.4623,5.74743L12.3421,5.74743C12.632,5.74743,12.8671,5.977679999999999,12.8671,6.26171ZM12.3421,9.57646L9.4623,9.57646C9.17235,9.57646,8.9373,9.806709999999999,8.9373,10.09074C8.9373,10.37477,9.17235,10.60503,9.4623,10.60503L12.3421,10.60503C12.632,10.60503,12.8671,10.37477,12.8671,10.09074C12.8671,9.806709999999999,12.632,9.57646,12.3421,9.57646ZM9.4623,8.55269L11.2144,8.55269C11.5043,8.55269,11.7394,8.32243,11.7394,8.0384C11.7394,7.75437,11.5043,7.52411,11.2144,7.52411L9.4623,7.52411C9.17235,7.52411,8.9373,7.75437,8.9373,8.0384C8.9373,8.32243,9.17235,8.55269,9.4623,8.55269ZM6.0932,8.06514L4.6022,8.06514C3.8497,8.06514,3.2372,8.66446,3.2372,9.40091L3.2372,10.84366C3.2372,11.12769,3.47225,11.35794,3.7622,11.35794C4.05215,11.35794,4.2872,11.12769,4.2872,10.84366L4.2872,9.40091C4.28797,9.23103,4.42877,9.09371,4.6022,9.09371L6.0932,9.09371C6.2669,9.093340000000001,6.40813,9.23076,6.4089,9.40091L6.4089,10.84366C6.4089,11.12769,6.64395,11.35794,6.9339,11.35794C7.22385,11.35794,7.4589,11.12769,7.4589,10.84366L7.4589,9.40091C7.45774,8.66286,6.84664,8.06514,6.0932,8.06514ZM3.7461,6.21166C3.74649,5.345219999999999,4.46321,4.64281,5.3477,4.64206C6.2311,4.64206,6.95,5.34629,6.95,6.21166C6.95,7.07703,6.2311,7.78057,5.3477,7.78057C4.463480000000001,7.77982,3.74687,7.07783,3.7461,6.21166ZM4.7961,6.21166C4.79649,6.51046,5.04407,6.75238,5.3491,6.752C5.65413,6.75162,5.90109,6.50909,5.9007,6.21029C5.90031,5.91148,5.65273,5.669560000000001,5.3477,5.66994C5.04267,5.67032,4.79571,5.91286,4.7961,6.21166ZM15,3.2L15,12.8C15,13.4617,14.4505,14,13.775,14L2.225,14C1.5495,14,1,13.4617,1,12.8L1,3.2C1,2.5382860000000003,1.5495,2,2.225,2L13.775,2C14.4505,2,15,2.5382860000000003,15,3.2ZM13.95,3.2C13.95,3.10532,13.8716,3.02857,13.775,3.02857L2.225,3.02857C2.12835,3.02857,2.05,3.10532,2.05,3.2L2.05,12.8C2.05,12.8946,2.1284,12.9714,2.225,12.9714L13.775,12.9714C13.8716,12.9714,13.95,12.8947,13.95,12.8L13.95,3.2Z" fill="currentColor" fillOpacity="1"/></g></g></svg>
          {t('header.personalInformation')}
        </div>
      )
    },
    {
      key: 'waxberry',
      label: (
        <div>
          <svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" fill="none" version="1.1" width="18" height="18" viewBox="0 0 18 18">
            <defs>
              <clipPath id="master_svg0_65_51779">
                <rect x="0" y="0" width="18" height="18" rx="0"/>
              </clipPath>
            </defs>
            <g clipPath="url(#master_svg0_65_51779)">
              <g><path d="M9.02642,9.46667L14.4244,6.32099L8.95852,2.82963L3.56052,6.25185L9.02642,9.46667ZM2.236485,6.28642L8.95852,2L15.7145,6.32099L8.99247,10.26173L2.236485,6.28642ZM15.4769,8.60247C15.6466,8.49876,15.8503,8.5679,15.9521,8.740739999999999C16.054000000000002,8.91358,15.9861,9.120989999999999,15.8163,9.224689999999999L8.99247,13.2L2.168585,9.19012C1.99883709,9.08642,1.9648874,8.879010000000001,2.0327867,8.70617C2.100686,8.53333,2.338334,8.49877,2.508082,8.5679L8.99247,12.3704L15.4769,8.60247ZM2.508083,11.3679L8.99247,15.1704L15.4769,11.3679C15.6466,11.2642,15.8503,11.33333,15.9521,11.50617C16.054000000000002,11.67901,15.9861,11.88642,15.8163,11.99012L8.99247,16L2.168585,11.99012C1.99883709,11.88642,1.9648874,11.67901,2.0327867,11.50617C2.100686,11.33333,2.338334,11.2642,2.508083,11.3679Z" fill="currentColor" fillOpacity="1"/></g></g>
          </svg>
          {t('menu.myWaxberry')}
        </div>
      )
    },
    {
      key: 'logout',
      label: (
        <div>
          <svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" fill="none" version="1.1" width="16" height="16" viewBox="0 0 16 16">
            <defs>
              <clipPath id="master_svg0_65_3372">
                <rect x="0" y="0" width="16" height="16" rx="0"/>
              </clipPath>
            </defs>
            <g clipPath="url(#master_svg0_65_3372)">
              <g><path d="M6.627962109375,10.559888799591064L7.640822109375,11.572768799591065L11.232522109375,7.981048799591065L7.640822109375,4.389338799591064L6.627962109375,5.402198799591064L8.481272109375,7.262698799591065L1.534927725775,7.262698799591065L1.534927725775,8.699388799591064L8.481282109375,8.699388799591064L6.627962109375,10.559888799591064ZM13.028412109375,1.5159687995910645L2.971602109375,1.5159687995910645C2.174240109375,1.5159687995910645,1.534912109375,2.1624687995910645,1.534912109375,2.9526587995910645L1.534912109375,5.826018799591065L2.971602109375,5.826018799591065L2.971602109375,2.9526587995910645L13.028412109375,2.9526587995910645L13.028412109375,13.009468799591064L2.971602109375,13.009468799591064L2.971602109375,10.136058799591064L1.534927725775,10.136058799591064L1.534927725775,13.009468799591064C1.534927725775,13.799568799591064,2.174256109375,14.446068799591064,2.971612109375,14.446068799591064L13.028412109375,14.446068799591064C13.818512109375,14.446068799591064,14.465112109375,13.799568799591064,14.465112109375,13.009468799591064L14.465112109375,2.9526587995910645C14.465012109375,2.1624847995910645,13.818512109375,1.5159687995910645,13.028412109375,1.5159687995910645Z" fill="currentColor" fillOpacity="1"/></g></g></svg>
          {t('header.logOut')}
        </div>
      )
    }
  ];

  return (
    // <div className="app-header">
    //   <Logo/>
    //   <div className="header-content">
    //     <div className="search">
    //       <SearchOutlined/>
    //       <Input
    //         placeholder={ t('search')+"~" }
    //         value={searchName}
    //         onChange={searchChange}
    //       />
    //     </div>
    //   </div>
    //   <div className="header-right">
    //     {userInfo
    //     ?<><Bell/>
    //     <Dropdown menu={{items,onClick: menuClick}}>
    //       <div className="userName">{currentUser.userName}<DownOutlined /></div>
    //     </Dropdown> </>
    //     :<Button type="primary" shape="round" onClick={goToLogin} style={{width:92,backgroundColor:'#4B3BDB'}}>登录</Button>
    //     }

    //   </div>
    // </div>
    <></>
  );
};

export default Header;
